package com.dhu.service.impl;

import com.dhu.dao.UserFollowMapper;
import com.dhu.dao.UserMapper;
import com.dhu.pojo.UserBarFollow;
import com.dhu.pojo.UserFollow;
import com.dhu.service.UserFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserFollowServiceImpl implements UserFollowService {
    @Autowired
    UserFollowMapper userFollowMapper;
    @Autowired
    UserMapper userMapper;

    @Override
    public UserFollow isFollowUser(int myId, int userId) {
        try {
            return userFollowMapper.isFollowUser(myId, userId);
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public int changeFollow(boolean isFollowUser, int myId, int userId) {
        try {
            if (isFollowUser) {
                // 我的关注-1
                userMapper.subFollowNum(myId);
                // 她的粉丝-1
                userMapper.subFunNum(userId);
                return userFollowMapper.disFollow(myId, userId);
            } else {
                // 我的关注+1
                userMapper.addFollowNum(myId);
                // 她的粉丝+1
                userMapper.addFunNum(userId);
                return userFollowMapper.follow(myId, userId);
            }
        } catch (Exception e) {
            return -1;
        }
    }
}
